package com.BaseDeDatos;
import gueei.binding.collections.ArrayListObservable;
import gueei.binding.observables.IntegerObservable;
import gueei.binding.observables.StringObservable;

import java.sql.*;
import com.Model.Comida;

public class Conexion {
	
	
	private static String dbUrl = "jdbc:mysql://us-cdbr-azure-west-a.cloudapp.net:3306/cdb_03531aa28e";
	private static String dbClass = "com.mysql.jdbc.Driver";
	private static String Usuario = "bbb0081f8e7902";
	private static String Clave = "01cbfbe9";
	

	public static void EjecutarPruebaDeConexion()
	{
		try {

			Class.forName(dbClass);

			Connection con = DriverManager.getConnection (dbUrl,Usuario,Clave);
			
			Statement s = con.createStatement(); 
			ResultSet rs = s.executeQuery ("select * from Comida");
			while (rs.next()) 
			{ 
				
			    System.out.println (rs.getInt (1) + " " + rs.getString (2)); 
			}
			con.close();
			} //end try

			catch(ClassNotFoundException e) {
			e.printStackTrace();
			}

			catch(SQLException e) {
			e.printStackTrace();
			}

	}
	public static ArrayListObservable<Comida> Comida_GetAll()
	{
		ArrayListObservable<Comida> Comidas = new ArrayListObservable<Comida>(Comida.class);
		try{
			
		
			Class.forName(dbClass);
			Connection con = DriverManager.getConnection (dbUrl,Usuario,Clave);
			Statement s = con.createStatement(); 
			ResultSet resultSets = s.executeQuery("call Comida_GetAll");
			while (resultSets.next()) 
			{ 
				Comida comida = new Comida();
				comida.ID = new IntegerObservable(resultSets.getInt("ID"));
				comida.Nombre = new StringObservable(resultSets.getString("Nombre"));
				Comidas.add(comida);
			}
		}

		catch(ClassNotFoundException e) {
		e.printStackTrace();
		}
		catch(SQLException e) {
			e.printStackTrace();
			}
		
			
		return Comidas;
	}
	

}  //end class
